package com.hisicom.scqxspxcjc.base.enums;

/**
 * @author:zhg
 * @description: 全局返回枚举类 命名规范 接口名+错误语义关联字
 * @date: 2017/8/23 上午10:00
 */
public enum ResultEnum {
    /**
     * 成功
     */
    SUCCESS(200, "successful"),
    ERROR401(401, "认证失败"),
    /**
     * 失败
     */
//    FAILURE(-1, "服务器错误"),
    /**
     * 公共错误
     */
    ERROR_SAVEORUPDATE_FAILURE(101, "操作失败，请稍后重试"),
    ERROR_NULL_POINTER_EXCEPTION_FAILURE(1, "空指针异常"),
    ERROR_PARAMETER_FAILURE(2, "参数错误"),
    ERROR_SIGNATURE_FAILURE(3, "签名认证失败"),
    ERROR_CONNECTION_NOT_PERMITTED_FAILURE(4, "连接被拒绝"),
    ERROR_CONNECTION_TIMED_OUT_FAILURE(5, "连接超时"),
    ERROR_CONNECTION_READ_OPERATION_TIMEOUT_FAILURE(6, "连接读操作超时"),
    ERROR_CONNECTION_WRITE_TIMEOUT_FAILURE(7, "连接写操作超时"),
    ERROR_NETWORK_MANAGEMENT_ERROR_FAILURE(8, "网关错误"),
    ERROR_REQUEST_FAILED_RETRY_FAILURE(9, "请求失败重试"),
    ERROR_REQUEST_FAILED_WAIT_FAILURE(10, "请求失败等待固定时间后重试"),
    ERROR_DATA_CONVERSION_ERROR_FAILURE(11, "数据转化错误"),
    ERROR_NO_PERMISSION_OPERATION_FAILURE(12, "无权限操作"),
    ERROR_UNKNOWN_ANOMALY_FAILURE(13, "未知异常"),
    ERROR_SYSTEM(-1, "系统异常"),
    /**
     * 文件数据错误
     */
    ERROR_SAVEORUPDATE_FAILURE1(101, "操作失败，请稍后重试"),
    ERROR_NOTNULL_FILE_PATH(300, "上传文件路径不能为空"),
    ERROR_NOTNULL_FILE_LABEL(301, "上传文件标签不能为空"),
    ERROR_NOTNULL_FILE_SORT(302, "上传文件序号不能为空"),
    ERROR_NOTNULL_FILE_BUCKETNAME(303, "上传文件bucketName不能为空"),
    ERROR_NOTNULL_FILE_BUSINESSID(304, "业务id不能为空"),
    ERROR_NOTNULL_FILE_FILEID(305, "文件id不能为空"),
    ERROR_NOTNULL_FILE(306, "文件不能为空"),
    ERROR_NOTFOUND_FILE(307, "文件未找到"),
    /*
     * 日期错误
     * */
    ERROR_DATE_NOTNULL(301, "日期错误");

    ResultEnum(String msg) {
        this.msg = msg;
    }

    private int code;
    private String msg;

    ResultEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ResultEnum getByKey(int key) {
        ResultEnum[] resultEnums = ResultEnum.values();
        for (ResultEnum resultEnum : resultEnums) {
            if (resultEnum.getCode() == key) {
                return resultEnum;
            }
        }
        return ResultEnum.ERROR_SYSTEM;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
